package com.hxzy.shop.controller.merchant;

import com.github.pagehelper.PageInfo;
import com.hxzy.shop.common.dto.merchant.req.AnnouncementMerchantListReq;
import com.hxzy.shop.common.dto.merchant.resp.AnnouncementDetailResp;
import com.hxzy.shop.constant.AuthConstant;
import com.hxzy.shop.dto.merchant.req.AnnouncementIdReq;
import com.hxzy.shop.dto.merchant.resp.AnnouncementClassificationListResp;
import com.hxzy.shop.dto.merchant.resp.AnnouncementMerchantDetailResp;
import com.hxzy.shop.feign.merchant.MerchantFeign;
import com.hxzy.shop.utils.WebUtil;
import com.hxzy.shop.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 功能描述 公告管理
 *
 * @author tonneyyy
 */
@RestController
@Api(tags = "公告管理")
@RequestMapping("/announcement")
public class AnnouncementController {

    /*******************商户相关***********************/
    @ApiOperation("公告 查看")
    @PostMapping("/announcementLook")
    public Result<AnnouncementDetailResp> announcementLook(@RequestBody AnnouncementIdReq req){
        HttpServletRequest request = WebUtil.getRequest();
        String merchantId = request.getHeader(AuthConstant.MERCHANT_ID);
        //从请求头中获取当前用户
        String userStr = request.getHeader(AuthConstant.USER_TOKEN_HEADER);
        return merchantFeign.announcementLook(req,userStr);
    }

    /**
     * 服务对象
     */
    @Resource
    private MerchantFeign merchantFeign;


    /**
     * 公告查看
     * @param announcementId
     * @return
     */

    @ApiOperation("公告 查看")
    @PostMapping("/announcementLook/{id}")
    public Result<AnnouncementDetailResp> announcementLook(@PathVariable(value = "id") Long announcementId){
        HttpServletRequest request = WebUtil.getRequest();
        String merchantId = request.getHeader(AuthConstant.MERCHANT_ID);
        //从请求头中获取当前用户
        String userStr = request.getHeader(AuthConstant.USER_TOKEN_HEADER);
        return merchantFeign.announcementLook(announcementId,userStr);
    }

    @ApiOperation("公告 获取商户当前未看公告条数")
    @PostMapping("/getAnnouncementNotLook")
    public Result<Integer> getAnnouncementNotLook(){
        return merchantFeign.getAnnouncementNotLook();
    }

    @ApiOperation("商户获得公告")
    @PostMapping("/getAnnouncementMerchant")
    public Result<PageInfo<AnnouncementMerchantDetailResp>> getAnnouncementMerchant(@RequestBody AnnouncementMerchantListReq req){
        return merchantFeign.getAnnouncementMerchant(req);
    }

    @ApiOperation("商户获得公告分类")
    @PostMapping("/getAnnouncementClassification/{isLook}")
    public Result<List<AnnouncementClassificationListResp>> getAnnouncementClassification(@PathVariable("isLook") Integer isLook){
        HttpServletRequest request = WebUtil.getRequest();
        String merchantId = request.getHeader(AuthConstant.MERCHANT_ID);
        return merchantFeign.getAnnouncementClassification(isLook,merchantId);
    }
}
